<?php
/**
 * 
 * 意见反馈
 * 
 * @category System
 * @author Steve Liu
 * @copyright Eshifang 
 */
class Web_Model_Feedback
{
	/**
	 * 默认数据库名
	 * 
	 * @var string
	 */
    private static $_table = 'feedback';
    
    /**
     * 获得所有反馈
     * 
     * @param int $start
     * @param int $limit
     * @return array
     */
    public static function getAll($start=0, $limit=100)
    {
        $feedbacks = Eren_Registry::get('DB')->table(self::$_table)
                                             ->orderBy('feedback_id', 'DESC')
                                             ->limit($start, $limit)->select();
        $feedbacks['total'] = Eren_Registry::get('DB')->table(self::$_table)->count();
        return $feedbacks;
    }
    
    /**
     * 校验反馈内容
     * 
     * @param string $content
     * @throws Eren_Exception
     */
    private static function _check($content)
    {
        if(empty($content)){
            throw new Eren_Exception('意见内容不可为空', -1);
        }
    }
    
    /**
     * 添加反馈内容
     * 
     * @param string $content
     * @return int
     */
    public static function add($content)
    {
        $content = Eren_Filter::addslashes($content);
        self::_check($content);
        $fields = array(
        'feedback_content' =>$content,
        'feedback_time'    =>Web_Model_Common::getNowTime(),
        );
        return Eren_Registry::get('DB')->table(self::$_table)->insert($fields);
    }
    
    /**
     * 删除反馈
     * 
     * @param int $id
     */
    public static function delete($id)
    {
        $id = intval($id);
        Eren_Registry::get('DB')->table(self::$_table)->where('feedback_id', '=', $id)->delete();
    }
}